package Algoritmos;

import grafoS.Graph;

/**
 * Gcol is a program to help users to learn a little about graph coloring, in
 * this software, you can learn some coloring algorithms, and add your own
 * algorithm for coloring.You can also learn BFS and DFS search. This tool, also
 * support the .col format from DIMACS (Center for Discrete Mathematics and
 * Theoretical Computer Science), so you can import a big graph and use all the
 * algorithms. Copyright (C) <2015> Clóvis Daniel Souza Silva, Samuel Silva de
 * Souza, Professor Leonardo Sampaio Rocha.
 * 
* This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
* This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
* You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 * contact: projetoGrafos@gmail.com
 */

/**
 * 
 * @author Daniel
 * @author Samuel
 */

/**
 * 
 * This class just keep the color of all vertices and
 * make a step by step coloring, where the user can choose the order.
 */
public class Guloso extends Algorithm {
    Graph gr;
    int[] cor;
    int [][] mA;
    public int[] ReturnColor(Graph g, int vertice){
        gr = g;
        cor = g.getcorC();
        mA = g.getGrafo();
        colorirBySteps(vertice);
        //g.setCor(cor);        
        return cor;
    }
    
    /**
    * coloringBySteps work coloring the vector cor by index.
    * 
    * @param v The index of the vertex to coloring.
    */
    public void colorirBySteps(int v) {
        int[][] Grafo = mA;
        int[] adjacentes = new int[gr.getN()];
        for (int i = 0; i < adjacentes.length; i++) {
            if (Grafo[v][i] == 1) {//se for adjacente
                if (cor[v] == cor[i] && cor[v] != 0) {// se tiver a mesma cor e a cor nao for 0
                    cor[v]++;//aumenta a cor do vertice atual
                    i = -1; // volta para o inicio da fila
                }
                if (cor[v] == 0) { // se a cor de v for 0
                    cor[v]++; // aumenta a cor
                    i = -1; // vai para o inicio da fila.
                }
            }

        }
        if (cor[v] == 0)
            cor[v]++;
        
    }
}
